if votes == 'all':
votes = query_db(basequery + ' order by id desc')
elif votes == 'archive':
- votes = query_db(basequery + ' and date_end < (?) order by id desc', [today])
+ votes = query_db(basequery + ' and is_terminated=1 order by id desc')
elif votes == 'current':
- votes = query_db(basequery + ' and date_end >= (?) order by id desc', [today])
+ votes = query_db(basequery + ' and is_terminated=0 order by id desc')
+ elif votes == 'waiting':
+ basequery = 'select votes.* from user_group join (' + basequery + ') as votes on votes.id_group = user_group.id_group where user_group.id_user = ?'
+ already_voted = 'select id_vote from user_choice join choices on user_choice.id_choice = choices.id where id_user = ?'
+ votes = query_db(basequery + ' and votes.id not in (' + already_voted + ') and is_terminated=0', [get_userid(), get_userid()])
else:
abort(404)
for vote in votes:
return False
return True
-
-
def can_vote(idvote, iduser=-1):
vote = query_db('select * from votes where id=?', [idvote], one=True)
if vote is None:
return False
- if iduser > 0:
- if can_see_vote(idvote, iduser):
- if not has_voted(idvote, iduser):
- if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
- return True
+ if not vote['is_finished']:
+ if iduser > 0:
+ if can_see_vote(idvote, iduser):
+ if not has_voted(idvote, iduser):
+ if query_db('select * from user_group where id_user = ? and id_group = ?', [iduser, vote['id']], one=True):
+ return True
return False
def has_voted(idvote, iduser=-1):
if 'public' in request.form.keys():
public = 1
isopen = 0
+ isterminated = 0
if request.form['status'] == 'Ouvert':
choices = query_db('select id_vote, count(*) as nb from choices where id_vote = ? group by id_vote', [voteid], one=True)
if choices is not None and choices['nb'] >= 2:
isopen = 1
else:
flash(u'Vous devez proposer au moins deux choix pour ouvrir le vote.', 'error')
- g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ? where id = ?',
- [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, voteid])
+ elif request.form['status'] == u'Terminé':
+ isterminated = 1
+ if vote['is_open']:
+ isopen = 1
+ g.db.execute('update votes set title = ?, description = ?, category = ?, is_transparent = ?, is_public = ?, is_open = ?, is_terminated = ? where id = ?',
+ [request.form['title'], request.form['description'], request.form['category'], transparent, public, isopen, isterminated, voteid])
g.db.commit()
vote = query_db('select * from votes where id = ?', [voteid], one=True)
flash(u"Le vote a bien été mis à jour.", "success")
create table groups (
id INTEGER primary key autoincrement,
- name TEXT,
+ name TEXT unique not null,
system INTEGER default 0 not null
);
is_multiplechoice INTEGER default 1 not null,
is_weighted INTEGER default 0 not null,
is_open INTEGER default 0 not null,
+ is_terminated INTEGER default 0 not null,
id_author INTEGER, -- :COMMENT:maethor:120528: not null ?
id_group INTEGER default 1 not null,
FOREIGN KEY(id_author) REFERENCES users(id)
insert into users (email, password, name, organization, is_admin, key) values ("admin@admin.fr", "d033e22ae348aeb5660fc2140aec35850c4da997", "Toto (admin) Tata", "World corp", 1, "test"); -- mdp = admin
insert into groups (id, name, system) values (1, "Tous", 1);
insert into groups (name) values ("CA");
-insert into groups (name) values ("Members");
+insert into groups (name) values ("Membres");
<input type="checkbox" name="public" {% if vote.is_public == 1 %} checked {% endif %}/>
Le vote est-il visible par tous ?
</label>
+ {% if not vote.is_terminated == 1 %}
<label class="checkbox">
<input type="checkbox" name="multiplechoice" {% if vote.is_multiplechoice == 1 %} checked {% endif %} disabled/>
Les votants peuvent-ils choisir plusieurs options ?
</label>
+ {% endif %}
</div>
</div>
</div>
<label class="control-label" for="status">Statut</label>
<div class="controls">
<select class="span2" name="status" id="status">
- {% if vote.is_open %}
- <option>Fermé</option>
- <option selected>Ouvert</option>
+ {% if vote.is_terminated == 1 %}
+ <option>Fermé</option>
+ <option>Ouvert</option>
+ <option selected>Terminé</option>
{% else %}
- <option selected>Fermé</option>
- <option>Ouvert</option>
+ {% if vote.is_open == 1 %}
+ <option>Fermé</option>
+ <option selected>Ouvert</option>
+ <option>Terminé</option>
+ {% else %}
+ <option selected>Fermé</option>
+ <option>Ouvert</option>
+ {% endif %}
{% endif %}
</select>
</div>
</form>
</div>
+ {% if not vote.is_terminated == 1%}
<div class="span5 well pull-right">
<fieldset><legend>Choix</legend>
<table class="table table-stripped table-condensed">
</table>
</fieldset>
</div>
+ {% endif %}
<div class="span5 well pull-right">
<fieldset><legend>Pièces jointes</legend>
{% for vote in votes %}
<tr>
<td>{{ vote.title }}</td>
- <td>{% if vote.is_open %}<span class="label label-success">Ouvert</span>{% else %}<span class="label label-important">Fermé</span>{% endif %}</td>
+ <td>{% if vote.is_terminated %}<span class="label label-sucess">Terminé</span>{% else %}{% if vote.is_open %}<span class="label label-info">Ouvert</span>{% else %}<span class="label label-important">Fermé</span>{% endif %}{% endif %}</td>
<td>{{ vote.date_end }}</td>
<td>{{ vote.groupname }}</td>
<td>{{ vote.category }}</td>
<a href="{{ url_for('user', userid=session.user.id) }}" class="btn"><i class="icon-user"></i> {{ session.user.name }}</a>
<a href="#" class="btn dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></a>
<ul class="dropdown-menu pull-right">
- <li><a href=""><i class="icon-comment"></i> Votes en attente</a></li>
+ <li><a href="{{ url_for('votes', votes='waiting') }}"><i class="icon-comment"></i> Votes en attente</a></li>
<li><a href="{{ url_for('user_edit', userid=session.user.id) }}"><i class="icon-cog"></i> Paramètres</a></li>
<li class="divider"></li>
<li><a href="{{ url_for('logout') }}"><i class="icon-off"></i> Déconnexion</a></li>
{% for choice in choices %}
<th>{{ choice.name }}</th>
{% endfor %}
+ {% if 'user' in 'session' %}
<th></th>
+ {% endif %}
</tr>
</thead>
{% else %}
<td class="no"></td>{% endif %}
{% endfor %}
- <td>{% if 'user' in session and user.userid == session.user.id %}<a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-mini btn-danger" title="Supprimer"><i class="icon-remove icon-white"></a>{% endif %}</td>
+ {% if 'user' in 'session' %}
+ <td>{% if user.userid == session.user.id %}<a href="{{ url_for('vote_deletechoices', idvote=vote.id, iduser=session.user.id) }}" class="btn btn-mini btn-danger" title="Supprimer"><i class="icon-remove icon-white"></a>{% endif %}</td>
+ {% endif %}
</tr>
{% endif %}
{% endfor %}
{% for choice in choices %}
<td>{{ choice.nb }}</td>
{% endfor %}
+ {% if 'user' in 'session' %}
<td></td>
+ {% endif %}
</tr>
{% endif %}
</tfoot>
{% endblock %}
{% block body %}
{% for vote in votes %}
- <article>
+ <div>
<div class="row well">
<div class="span4">
<h3><a href="{{ url_for('vote', idvote=vote.voteid) }}">{{ vote.title }}</a></h3>
{{ vote.description|safe }}
</p>
</div>
- </article>
+ </div>
{% else %}
<div class="alert">Il n'y a pas encore de votes. Désolé.</div>
{% endfor %}